package com.ruoyi.develop.goodsSalebuy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.develop.goodsSaledo.domain.GoodsSaledo;
import com.ruoyi.develop.lvRukumingxi.domain.LvRukumingxi;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.goodsSalebuy.domain.GoodsSalebuy;
import com.ruoyi.develop.goodsSalebuy.service.IGoodsSalebuyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购单Controller
 * @author qh
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/goodsSalebuy/goodsSalebuy")
public class GoodsSalebuyController extends BaseController {
    @Autowired
    private IGoodsSalebuyService goodsSalebuyService;

    /**
     * 查询采购单列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:query')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSalebuy entity) {
        startPage();
        List<GoodsSalebuy> list = goodsSalebuyService.selectList(entity);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:query')")
    @GetMapping("/listByQinggou")
    public TableDataInfo listByQinggou(GoodsSalebuy entity) {
        startPage();
        List<GoodsSalebuy> list = goodsSalebuyService.listByQinggou(entity);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:query')")
    @GetMapping("/listByCgallid")
    public TableDataInfo listByCgallid(GoodsSalebuy entity) {
        startPage();
        List<GoodsSalebuy> list = goodsSalebuyService.listByCgallid(entity);
        return getDataTable(list);
    }

    /**
     * 导出采购单列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:export')")
    @Log(title = "采购单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSalebuy entity) {
        List<GoodsSalebuy> list = goodsSalebuyService.selectList(entity);
        ExcelUtil<GoodsSalebuy> util = new ExcelUtil<GoodsSalebuy>(GoodsSalebuy. class);
        util.exportExcel(response, list, "采购单数据");
    }

    /**
     * 获取采购单详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(goodsSalebuyService.selectById(id));
    }

    /**
     * 新增采购单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:add')")
    @Log(title = "采购单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GoodsSalebuy entity) {
        return toAjax(goodsSalebuyService.insert(entity));
    }

    /**
     * 修改采购单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:edit')")
    @Log(title = "采购单", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody GoodsSalebuy entity) {
        return toAjax(goodsSalebuyService.update(entity));
    }

    /**
     * 删除采购单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSalebuy:remove')")
    @Log(title = "采购单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(goodsSalebuyService.deleteByIds(ids));
    }

    @PostMapping("/insertForCg")
    public AjaxResult insertForCg(@Validated @RequestBody GoodsSaledo entity) {
        goodsSalebuyService.insertBatch(entity);
        return AjaxResult.success("选择完成！");
    }

    @PostMapping("/insertForBuy")
    public AjaxResult insertForBuy(@Validated @RequestBody GoodsSaledo entity) {
        goodsSalebuyService.insertBuyBatch(entity);
        return AjaxResult.success("选择完成！");
    }


    /** * 采购退回 */
    @PostMapping("/insertForReturn")
    public AjaxResult insertForReturn(@Validated @RequestBody LvRukumingxi rukumingxi) {
        goodsSalebuyService.insertForReturn(rukumingxi);
        return AjaxResult.success("选择完成！");
    }













}
